package com.tofacebook.proxy.daili;

import com.tofacebook.proxy.model.Dept;
import com.tofacebook.proxy.model.Emp;
import com.tofacebook.proxy.service.DeptService;
import com.tofacebook.proxy.service.EmpService;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class DeptStaticProxy implements DeptService {
    //要代理的接口
    private DeptService deptService;

    //通过有参的构造方实例化DeptService这个接口对应的实现类
    public DeptStaticProxy(DeptService deptService) {
        this.deptService = deptService;
    }

    public int saveDeptInfo(Dept emp) {
        //日志信息放在静态代理实现类中
        log.info("操作之前：{}",emp);
        //访问主体的业务代码开始-------------------
        int num = deptService.saveDeptInfo(emp);
        //访问主体的业务代码结束--------------------
        log.info("操作之后：{}",emp);
        return num;
    }

    public Dept queryDeptByDeptId(Long empId) {
        log.info("操作之前：{}",empId);
        Dept emp = deptService.queryDeptByDeptId(empId);
        log.info("操作之后：{}",emp);
        return emp;
    }
}
